define(function(require, exports, module){
	require("resource/js/mobile/awesome/css/font-awesome.css");
	require("resource/js/mobile/css/textbox.css");
	require("resource/js/mobile/css/combobox.css");
	require("resource/js/mobile/jquery.textbox.js");
	require("resource/js/mobile/jquery.combobox.js");
	var ajax = require("resource/js/component/ajax.js");
	var urlTool = require("resource/js/component/urlTool.js");
	var actcont = require("oa/act/js/actcont.js");
	var submit = require("oa/act/mobile/js/submitMobile.js");
	var getDATE = function(jq) { //初始化日期控件
		function stopBubble(e) {
			if (e && e.stopPropagation)
				e.stopPropagation()
			else
				window.event.cancelBubble = true
		}
		stopBubble(this)
		jq.init();
		var result = null;
		var btns = $('.btnDateCla');
		btns.each(function(i) {
			btns[i].removeEventListener('tap', getDATE, false);
			btns[i].addEventListener('tap', function() {
				var res = this;
				var optionsJson = this.getAttribute('data-options') || '{}';
				var options = eval('(' + optionsJson + ')');
				var id = this.getAttribute('class');
				result = jq("#" + id);
				/*
				 * 首次显示时实例化组件
				 * 示例为了简洁，将 options 放在了按钮的 dom 上
				 * 也可以直接通过代码声明 optinos 用于实例化 DtPicker
				 */
				var picker = new jq.DtPicker(options);
				if (!$(".mui-dtpicker").hasClass("mui-active")) {
					picker.show(function(rs) {
						res.value = rs.text;
						if (rs.type != "date") {
							res.value += ":00";
						}
						setOverTime(res.id, res.value);
						picker.dispose();
					});
				}
			}, false);
		});
	}
	var initpage = function(){
		var colhtml="";
		var data = localStorage.getItem("key");
		    dataJosn =JSON.parse(data);
		    if(dataJosn.data.tab.tablename){
		    	$("<h1>"+dataJosn.data.tab.tablename+"</h1>").appendTo($(".approvalDetail"));
		        if(dataJosn.data.tab.ismore=="1"){
		        	colhtml="<ul>";
		        	colhtml= initResultData(dataJosn.data,colhtml);
		        	colhtml +="</ul>";
		        }else{
		        	colhtml+=initTableData(dataJosn.data);
		        }
		        $(colhtml).appendTo($(".approvalDetail"));
		    }else{
		    	$("#processKey").val(dataJosn.whole.key);
		    	$("#processNodeId").val(dataJosn.whole.processNodeId);
		    	$("#processInstanceId").val(dataJosn.whole.processInstanceId);
		    	$("#taskId").val(dataJosn.whole.taskId);
		    	$("#currentUserId").val(dataJosn.whole.currentUser);
		    	$("#busenessId").val(dataJosn.whole.busenessId);
		    	$("<h1>"+dataJosn.data.tab.shortNameCh+"</h1>").appendTo($(".approvalDetail"));
					var $tab;
					if(localStorage.getItem("id")){
						$tab = $('#suggestion');
					}else{
						$tab = $("#subsTab");
					}
					var html = "";
					$tab.append( "<input type='hidden' id='tab-" + dataJosn.data.tab.tableKey + "' value='" + dataJosn.data.tab.operType + "' />");
					var isMore = dataJosn.data.tab.isMore;
					var tabName = dataJosn.data.tab.tableKey;
					if (dataJosn.data.cols) {
						if (isMore == "1") { //单行表单数据
							tabMore = false;
							html += "<ul class='inputStyle'>";
							html = initFormData(dataJosn.data, html);
							html += "</ul>";
							$tab.append(html);
						} else { //多行表格数据
							tabMore = true;
							html += initMoreTableData(dataJosn.data, 0);
							$tab.append(html);
							$tab.parent().append("<div class='sub-addBtn'><input type='button' value='+ 新增' tabKey='" + tabName + "' id='addTableBtn_" + tabName + "' /></div>");
							document.getElementById("addTableBtn_" + tabName).cols = JSON.stringify(dataJosn.data.cols);
							document.getElementById("addTableBtn_" + tabName).subs = JSON.stringify(dataJosn.data);
						}
					}
					
					btnsAdd(dataJosn.whole.btns);
				
//					if (!processInstanceId && index == datas.subs.length) {
//						getDATE(mui);
//						//$('#subsForm').show();
//						$tab.parent().show();
//					}
				}
			addFormEvent();
		
	}
	
	var btnsAdd = function(btns){
		if (btns && btns.length > 0) { //加载button数据
			var btnsHtm = '';
			var showBtnNum = 4;
			$.each(btns, function(i, btn) {
				if(i>showBtnNum-1){
					return false;
				} 
				var btnId = btn.id || '';
				var btnClass = btn['class']||'';
				var btnName = btn.name || '';
				var options = btn.options || '';
				//btnsHtm += '<input id="' + btnId + '" type="button" class="button '+btnClass+'" value="' + btnName + '"  data-options="'+options+'" />';
				if(!localStorage.getItem("id")){
					btnsHtm += '<input id="' + btnId + '" type="button" class="button btn-create '+btnClass+'" value="' + btnName + '"  data-options="'+options+'"/>';	
				}else{
					btnsHtm += '<a id="' + btnId + '" class="approval-button '+btnClass+'"  data-options="'+options+'">'
	   				+'<span>'+btnName+'</span>'
		   			+'</a>';
				}
			});
			$("#btns").html(btnsHtm);
			//追加更多按钮
			if(localStorage.getItem("id") && btns.length > showBtnNum){
				var moreBtn = '<a href="javascript:void(0)"  class="approval-button" id="moreBtns">'
	   				+'<span>更多</span>'
		   			+'</a>';
				$("#btns").append(moreBtn);
				initMoreBtns(datas.btns,showBtnNum+1);
			}
		}
	}
	
	//初始化按钮弹窗
	var initMoreBtns = function(btns,startIndex){
		var html='';
		if(btns&&btns.length>0){
			var btnId='';
			var btnClass='';
			var btnName ='';
			var options ='';
			for(var i=0;i<btns.length;i++){
				if(i>=startIndex){
					btnId = btns[i].id || '';
					btnClass = btns[i]['class']||'';
					btnName = btns[i].name || '';
					options = btns[i].options || '';
					html += '<li id="' + btnId + '" class="'+btnClass+'" data-options="'+options+'">'+btnName+'</li>'
				}
			}
		}
		$('#btnsDlg .dlg-body').append(html);	
		$('#btnsDlg').css('margin-left',-($('#btnsDlg').width()/2));
		$('#btnsDlg').css('margin-top',-($('#btnsDlg').height()/2));	
		$('#btnsDlg .dlg-cancel').unbind('click');
		$('#btnsDlg .dlg-cancel').bind('click',function(){
			$('#btnsDlg').hide();
			hideMask();
		});

	};
	
	function initTableData(subs,num){
		//封装表格列 数据
		var columnsList =[];
		var tabHtml="";
		if(subs.cols&&subs.cols.length>0){
			 var tabName=subs.tab.tablekey;
			if(subs.data&&subs.data.length>0){
				$.each(subs.data,function(i,data){
					 tabHtml+= "<ul class='list marginBottom10'><caption><div class='sub-title'>"+subs.tab.tablename+"明细(<span>"+(i+1)+"</span>)</div><caption>";
					 tabHtml=initResultData(subs,tabHtml,i); 
					 tabHtml+="</ul>";
				});
			}
		}
		return tabHtml;
	}
	
	function initMoreTableData(subs, num) {
		//封装表格列 数据
		var columnsList = [];
		var tabHtml = "";
		//		var isProcess= $("#subIsProcess").val();
		if (subs.cols && subs.cols.length > 0) {
			var tabName = subs.tab.tableKey;
			// var width=0;
			//			 var colsStr = JSON.stringify(subs.cols);
			tabHtml = "<ul sign='processTable' class='form_m inputStyle' name='" + tabName + "' id='" + tabName + "-" + num + "'>" +
				"<caption><div class='sub-title' style='border-radius:0;'>" + subs.tab.shortNameCh + "明细(<span>" + (num + 1) + "</span>)<input type='button' value='删除' style='float:right;display:" + (num == 0 ? "none" : "") + "' class='sub-deleteBtn' /></div>" +
				"</caption>";
			tabHtml = initFormData(subs, tabHtml, "subIsProcess", num);
		}
		if (tabHtml != "") {
			tabHtml += "</ul>";
		}
		return tabHtml;
	}
	
	function initResultData(main,html,num){
		var len = main.cols.length;
		var ind = 0;
		if(num!=undefined&&num!=null){
			ind=num;
		}
		$.each(main.cols,function(i,col){
			var show =  !(col.showtype==actcont.showType.FORM_SHOWTYPE_HIDDEN);
			show = main.data && main.data.length > 0 && main.data[0];
			var colId =col.colname;
			//隐藏域处理//
			if (col.showtype==actcont.showType.FORM_SHOWTYPE_HIDDEN){
			//多行文本处理//
			}else if (col.showtype==actcont.showType.FORM_SHOWTYPE_TEXTAREA) {
				html+="</li><li"+(show?"":" style='display:none'")+"><span class='col-name'>"+col.colnamech+"：</span><span class='col-val'>"+((main.data[ind]!=null&&main.data[ind][''+colId+'']!=undefined)?main.data[ind][''+colId+'']:"")+"</span>";
			//其他//
			}else if(col.showtype==actcont.showType.FORM_SHOWTYPE_FILE){
				html+="</li><li"+(show?"":" style='display:none'")+"><span class='col-name'>"+col.colnamech+"：</span>";
				if(main.data!=null&&main.data.length>0&&main.data[ind]!=null&&main.data[ind][''+colId+'']!=undefined&&main.data[ind][''+colId+'']!=""&&main.dataaddon != null){
					var files = main.dataaddon[''+colId+''];
					if(files&&files.length>0){
						var fileDownload='<div class="fileList col-val">';
						for(var i=0;i<files.length;i++){
							var file = files[i];
							var fileUrl = file.fileUrl;
							var fileName = file.fileName+"."+file.fileExt;
							//var size = getFileSize(file.fileSize);
							var icon = getFileIcon(file.fileExt);
							//fileDownload +="<a href='javascript:window.open (\""+BASEPATH+fileUrl+"\")'>"+fileName+"</a>&nbsp;&nbsp;";
							fileDownload += '<div class="fileSet" data-url='+fileUrl+'>'
			   					+ '<div class="'+icon+'">'
			   						+'<p style="margin-bottom:0;color:#333;">'+fileName+'</p>'
			   						/*+'<p class="prompt" style="margin-bottom:0;">'+size+'</p>'*/
		   						+'</div></div>';
						}
						html += fileDownload;
					}
				}	
			}else{
				html+="</li><li"+(show?"":" style='display:none'")+"><span class='col-name'>"+col.colnamech+"：</span><span class='col-val'>"+((main.data[ind]!=null&&main.data[ind][''+colId+'']!=undefined)?main.data[ind][''+colId+'']:"")+"</span>";
			}
			html+="</li>"
		});
		return  html;
	}
	
	function initFormData(main, html, isProcessId, num) {
		var len = main.cols.length;
		var col_idex = 0;
		var tabName = main.tab.tableKey;
		var isProcess = $("#" + isProcessId).val();
		var className = "textbox-text";
		if (num != undefined && num != null) {
			className = "tab-text";
		}
		$.each(main.cols, function(i, col) {
			var show =  !(col.showType==actcont.showType.FORM_SHOWTYPE_HIDDEN);
			if (col_idex == 0) {
				html += "<li"+(show?"":" style='display:none'")+">";
			} else {
				html += "</li><li"+(show?"":" style='display:none'")+">";
			}
			var colId = tabName + "-" + col.colName;
			if (num != undefined && num != null) {
				colId = colId + "-" + num;
			}
			var isRequire = "";
			//判断是否必填项//
			if (col.isRequire != null && col.isRequire == 0) {
				isRequire = "<span class='star'>*</span>";
			}
			if (col.isProcess != null && col.isProcess == 0) {
				isProcess = isProcess + colId + ","
			}

			var properties = "";

			if(col.properties&&col.properties!=undefined&&col.properties!=null){
				properties = eval("("+col.properties+")");

			}

			var placeholder = "请输入" + col.colNameCh;

			if (undefined != properties.prompt && null != properties.prompt) {
				placeholder = properties.prompt;
			}

			var dataOptions = "{'showType':'" + col.showType + "','checkType':'" + (col.checkType != undefined ? col.checkType : "") + "','id':'" + colId + "','dataId':'" + col.dataId +"','dataSource':'"+col.dataSource+ "','colNameCh':'" + col.colNameCh + "','colName':'" + col.colName + "','isRequire':'" + (col.isRequire != undefined ? col.isRequire : "1") + "','dataOnchange':'" + (col.dataOnchange != undefined ? col.dataOnchange : "") + "'}";

			if (col.showType==actcont.showType.FORM_SHOWTYPE_HIDDEN){
				html+='<span style="height: 0px;"><input type="hidden" class="'+className+'" id="'+colId+'" name="'+colId+'" vlaue=""  options="'+dataOptions+'" /></span>';
			//多行文本处理//
			}else if (col.showType==actcont.showType.FORM_SHOWTYPE_TEXTAREA) {
				html+='<span>'+isRequire+col.colNameCh+'</span><span>'+
						'<textarea rows="3" cols="20" id="'+colId+'" name="'+colId+'" class="'+className+'"  placeholder="'+placeholder+'"  options="'+dataOptions+'" maxlength="'+col.colLength/2+'"></textarea>'+
						'</span>';
			//文本框处理//
			}else if(col.showType==actcont.showType.FORM_SHOWTYPE_TEXT){
				html+='<span>'+isRequire+col.colNameCh+'</span><span><input type="text" placeholder="'+placeholder+'"  options="'+dataOptions+'"  id="'+colId+'" name="'+colId+'" value="" class="'+className+'"   maxlength="'+col.colLength/2+'"/></span>';
			//数字处理//
			}else if(col.showType==actcont.showType.FORM_SHOWTYPE_INTEGER){

				if(undefined != properties.min && null != properties.min){
					html+='<span>'+isRequire+col.colNameCh+'</span><span><input type="number" placeholder="'+placeholder+'"  options="'+dataOptions+'"  id="'+colId+'" name="'+colId+'"  class="'+className+'"  min="'+properties.min+'" onblur="javascript:this.value=(this.value==\'\'?\'\':parseFloat(this.value < this.min?this.min:this.value).toFixed(0))"/></span>';
				}else{
					html+='<span>'+isRequire+col.colNameCh+'</span><span><input type="number" placeholder="'+placeholder+'"  options="'+dataOptions+'"  id="'+colId+'" name="'+colId+'"  class="'+className+'"  onblur="javascript:this.value=(this.value==\'\'?\'\':parseFloat(this.value).toFixed(0))"/></span>';
				}
			//浮点数字处理//
			}else if(col.showType==actcont.showType.FORM_SHOWTYPE_NUMBER){
				if(undefined != properties.min && null != properties.min){
					html+='<span>'+isRequire+col.colNameCh+'</span><span><input type="number" placeholder="'+placeholder+'"  options="'+dataOptions+'"  id="'+colId+'" name="'+colId+'"  class="'+className+'" min="'+properties.min+'" onblur="javascript:this.value=(this.value==\'\'?\'\':parseFloat(this.value < this.min?this.min:this.value).toFixed(2))"/></span>';
				}else{
					html+='<span>'+isRequire+col.colNameCh+'</span><span><input type="number" placeholder="'+placeholder+'"  options="'+dataOptions+'"  id="'+colId+'" name="'+colId+'"  class="'+className+'"  onblur="javascript:this.value=(this.value==\'\'?\'\':parseFloat(this.value).toFixed(2))"/></span>';
				}
				//下拉框处理//
			} else if (col.showType == actcont.showType.FORM_SHOWTYPE_SELECT) {
				html += '<span>' + isRequire + col.colNameCh + '</span><span>' +
					'<input  options="' + dataOptions + '" placeholder="' + placeholder + '" type="text" id="' + colId + '"  class="' + className + '" name="' + colId + '" />' +
					'</span>';
				//多选下拉框处理//
			} else if (col.showType == actcont.showType.FORM_SHOWTYPE_MSELECT) {
				html += '<span>' + isRequire + col.colNameCh + '</span><span><input placeholder="' + placeholder + '"   options="' + dataOptions + '"  type="text" id="' + colId + '" name="' + colId + '" class="' + className + '" /></span>';
				//单选树处理//
			} else if (col.showType == actcont.showType.FORM_SHOWTYPE_TREE) {
				html += '<span>' + isRequire + col.colNameCh + '</span><span><input placeholder="' + placeholder + '"  options="' + dataOptions + '"  type="text" id="' + colId + '" name="' + colId + '" class="' + className + '"/></span>';
				//多选处理//
			} else if (col.showType == actcont.showType.FORM_SHOWTYPE_MTREE) {
				html += '<span>' + isRequire + col.colNameCh + '</span><span><input placeholder="' + placeholder + '" options="' + dataOptions + '"  type="text" id="' + colId + '" name="' + colId + '" class="' + className + '" /></span>';
				//文件上传处理//
			} else if (col.showType == actcont.showType.FORM_SHOWTYPE_FILE) {
				html += '<span>' + isRequire + col.colNameCh + '</span><span ><input placeholder="' + placeholder + '" options="' + dataOptions + '"  type="file" id="' + colId + '" name="' + colId + '" class="' + className + '" /></span>';
				//日期 年月日处理//
			} else if (col.showType == actcont.showType.FORM_SHOWTYPE_DATEBOX) {
				//require.async("resource/js/component/mobileDate.js",function(jeDate){});
				html += '<span>' + isRequire + col.colNameCh + '</span><span>' +
					'<input class="' + className + ' btnDateCla mui-btn mui-btn-block"  options="' + dataOptions + '" data-options="{\'type\':\'date\',\'beginYear\':2010,\'endYear\':2116}"  placeholder="' + placeholder + '"  id="' + colId + '" name="' + colId + '" type="text" placeholder="请选择"  readonly />' +
					'</span>';
				//日期 年月日时分秒处理//
			} else if (col.showType == actcont.showType.FORM_SHOWTYPE_DATETIMEBOX) {
				//require.async("resource/js/component/mobileDate.js",function(jeDate){});
				html += '<span>' + isRequire + col.colNameCh + '</span><span>' +
					//				'<input class="'+className+' datainp"  options="'+dataOptions+'" placeholder="'+placeholder+'"  id="'+colId+'" name="'+colId+'" type="text" placeholder="请选择"  readonly  class="'+className+'" /><div type="button"  class="dateClass" onClick="jeDate({dateCell:\'#'+colId+'\',isTime:true,format:\'YYYY-MM-DD hh:mm:ss\'},this)"></div>'+
					'<input class="' + className + ' btnDateCla mui-btn mui-btn-block"  options="' + dataOptions + '" placeholder="' + placeholder + '" data-options="{\'beginYear\':2010,\'endYear\':2116}"  id="' + colId + '" name="' + colId + '" type="text" placeholder="请选择"  readonly />' +
					'</span>';
			}else if(col.showType == actcont.showType.FORM_SHOWTYPE_BOOKS){
				html+='<span>'+isRequire+col.colNameCh+'</span><span>'
				+'<input type="text" readonly placeholder="'+placeholder+'"  options="'+dataOptions+'"  id="books-'+colId+'" name="books-'+colId+'" value="" class="'+className+'"   maxlength="'+col.colLength/2+'"/>'
				+'<i class="input-clear"></i>'
				+'<input type="hidden" id="'+colId+'" name="'+colId+'" value="">'
				+'</span>';
			}
			col_idex++;
		});
		$("#" + isProcessId).val(isProcess);
		return html + "</tr>";
	}
	
	function addFormEvent() {
		$("input:button[id*='addTableBtn_']").bind("click", function(e) {
			var tab = $("#subsTab");
			var html = tab.html();
			var tabId = e.target.id;
			var num = $(".sub-deleteBtn").size();
			var subs = document.getElementById(tabId).subs;
			var tableKey = document.getElementById(tabId).getAttribute('tabKey');
			$("#subsTab").append(initTableData(JSON.parse(subs), $(".sub-deleteBtn").size()));
			getDATE(mui);
			addInputEvent($("#" + tableKey + "-" + num).find(".tab-text"));
			$(".sub-deleteBtn").unbind("click");
			$(".sub-deleteBtn").bind("click", function(e) {
				$(this).parent().parent().remove();
				resetRowTab("subsTab");
			});
		});
		addInputEvent($(".processForm").find(".textbox-text"));
		addInputEvent($(".subsForm").find(".textbox-text"));
		addInputEvent($(".subsForm").find(".tab-text"));
		loadBtns();
	}
	
	function addInputEvent(ins) {
		$.each(ins, function(i, input) {
			var opt = eval('(' + $(input).attr('options') + ')');
			var showType = opt.showType;
			
			if (showType == actcont.showType.FORM_SHOWTYPE_SELECT && opt.dataId && opt.dataId != '') {
			
				require("resource/js/mobile/awesome/css/font-awesome.css");
				require("resource/js/mobile/css/textbox.css");
				require("resource/js/mobile/css/combobox.css");
				require("resource/js/mobile/jquery.textbox.js");
				require("resource/js/mobile/jquery.combobox.js");
				var dataId = opt.dataId;
				if (dataId.indexOf("UC") == 0) { //用户自定义流程下拉框
					comboxLoad(opt.id, "actcode", false, dataId);
				}else if(dataId == "link"){
					if(opt.dataSource){
						comboxLoad(opt.id, null,false,null,BASEPATH+opt.dataSource);
					}
				}else if(dataId == "basecode"){
					//加载下拉框数据   
					var dataSource = opt.dataSource;
					if(dataSource && dataSource != ''){
						var source = dataSource.split(',');
						comboxLoad(opt.id, dataId,false, getComboxParam(source));
					}else{
						comboxLoad(opt.id, dataId,false, '');
					}
				}
				
				//绑定联动字段
				var dataOnchange = opt.dataOnchange;
				if(dataOnchange && $('#'+dataOnchange).length > 0){
					var $obj = $('#'+opt.id);
					var $target = $('#'+dataOnchange);
					var options = eval('('+$target.data('options')+')');
					if(options.showType == actcont.showType.FORM_SHOWTYPE_SELECT){
						$obj.combobox({
							onChange:function(newVal,oldVal){
								comboxLoad(dataOnchange, options.dataId,false, newVal);
							}
						});
					}else if(options.showType == actcont.showType.FORM_SHOWTYPE_HIDDEN){
						$obj.combobox({
							onChange:function(newVal,oldVal){
								$target.val(newVal);
							}
						});
					}
				}
			} else if (showType == actcont.showType.FORM_SHOWTYPE_MSELECT && opt.dataId && opt.dataId != '') {

				comboxLoad(opt.id, "actcode", true, opt.dataId);
			} else if (showType == actcont.showType.FORM_SHOWTYPE_TREE && opt.dataId && opt.dataId != '') {
				treeLoad(input.id, opt.dataId, opt.dataOnchange, "radio");
			} else if (showType == actcont.showType.FORM_SHOWTYPE_MTREE && opt.dataId && opt.dataId != '') {
				treeLoad(input.id, opt.dataId, opt.dataOnchange, "checkbox");
			} else if (showType == actcont.showType.FORM_SHOWTYPE_FILE) {
				if (appCheck()) {
					//上传文件
					require.async(["resource/js/mobile/awesome/css/font-awesome.css", "resource/js/mobile/css/textbox.css", "resource/js/mobile/css/upload.css",
						"resource/js/mobile/jquery.upload.js", "resource/js/mobile/jquery.textbox.js"
					], function(upload) {
						$(input).upload({
							type:"file"
						});
					});
				} else {
					//上传文件
					require.async(["resource/js/mobile/awesome/css/font-awesome.css", "resource/js/mobile/css/textbox.css", "resource/js/mobile/css/upload.css",
						"resource/js/mobile/jquery.uploadios.js", "resource/js/mobile/jquery.textbox.js"
					], function(upload) {
						$(input).upload({
							buttonText: "",
							exts: ['png', 'gif', 'jpg', 'mp4', 'txt', 'doc', 'docx', 'xsl', ''],
						});
					});
				}
			}else if(showType== actcont.showType.FORM_SHOWTYPE_BOOKS){
				var books = $(input).vitoBooks({
					checkType:'radio',
					userType:opt.dataSource,
					closed: true,
					onSave:function(nodes){
						var text = '';
						var value = '';
						$.each(nodes,function(i,item){
							text += item.name +',';
							value += item.id + ',';
						});
						if($('#'+opt.id).val().indexOf(value.substring(0,text.length-1))>-1 && $(input).val().indexOf(text.substring(0,text.length-1))>-1){
							$(".error").text("不能重复选择").show().delay(2000).hide(0);
							return
						}
						if(opt.dataId == 'checkbox'){
							text = text + $(input).val();
							value = value + $('#'+opt.id).val();
						}
						text = text.substring(0,text.length-1);
						value = value.substring(0,value.length-1);
						$(input).val(text);
						$('#'+opt.id).val(value);
						text.length>0 && $(input).siblings('.input-clear').css('display','inline');
					}
				});
				$(input).unbind('click');
				$(input).bind('click',function(){
					books.vitoBooks('open');
				});
				$(input).siblings('.input-clear').unbind('click');
				$(input).siblings('.input-clear').bind('click',function(){
					$(input).val("");
					$('#'+opt.id).val("");
					$(this).hide();
				});
			}
		});
	}
	function comboxLoad(id, dataId, isMutil, param,url) {
		$("#" + id).combobox({
			url:url || BASEPATH + "/base/authoriza/conmonData/queryDataNoCache.htm?queryId=" + dataId + "&param=" + param,
			dataFilter: function(data) {
				if (data.data != undefined) {
					return data.data;
				} else {
					return "";
				}
			},
			textFiled: "text",
			valueFiled: "id",
			isMutil: isMutil
		});
	}
	function getComboxParam(dataOnchanges) {
		var param = "";
		$.each(dataOnchanges, function(i, dataOnchange) {
			if ($("#" + dataOnchange).length > 0) {
				param += $("input[name='" + dataOnchange + "']").val();
			} else {
				param += dataOnchange;
			}
			if (i > 0) {
				param += ",";
			}
		});
		return param;
	}

	function treeLoad(id, dataId, param, type) {
		require.async(["resource/js/mobile/awesome/css/font-awesome.css", "resource/js/mobile/css/textbox.css", "resource/js/mobile/css/combobox.css", "resource/js/mobile/css/listview.css",
			"resource/js/mobile/jquery.listview.js", "resource/js/mobile/jquery.textbox.js", "resource/js/mobile/jquery.listbox.js"
		], function(listview, textbox, listbox) {
			$("#" + id).listbox({
				url: BASEPATH + "/base/authoriza/conmonData/queryDataNoCache.htm?queryId=" + dataId + "&param=" + param,
				dataFilter: function(data) {
					return data.data;
				},
				view: {
					idKey: "id",
					nameKey: "name",
					pidKey: "pid"
				},
				check: {
					type: type,
					radio: {
						type: "all"
					}
				}
			});
		});
	}
	
	function trim(res){
		if(res!=undefined && res!=null && res!=""){
			return res;
		}else{
			return "";
		}
	};
	function getFileSize (size){
		var result = size < 1024 ? size.toFixed(2)+'B' 
   				: size < (1024*1024) ? (size/1024).toFixed(2)+'KB'
				:(size/(1024*1024)).toFixed(2)+'MB';
   		return result;
	}
	function getFileIcon(ext){
		var iconClass='';
		if(/^(gif|png|jpg|jpeg|bmp)$/i.test(ext)){
			iconClass = 'pictureIcon';
		}else if(/^(mp3|mp4|avi|dat|mkv|flv)$/i.test(ext)){
			iconClass = 'mediaIcon';
		}else{
			iconClass = 'fileIcon';
		}
		return iconClass;
	}
	
	function loadBtns() {
		$("#cancel").click(function() {
			$(".Mask").hide();
			$(".alertDelete").hide();
		});
		var urlTool = require("resource/js/component/urlTool.js");
		var processInstanceId = urlTool.getParam("processInstanceId");
		var bussId = $("#busenessId").val();
		//setUrlParam();
		//当前登录用户ID
		var currentUser = $("#currentUserId").val();
		var taskId = urlTool.getParam("taskId");
		var key = urlTool.getParam("key");
		var processNodeId = $("#processNodeId").val();
		var businessId = $("#busenessId").val();
		
		//绑定打印按钮事件
		  if(typeof($("#printBtn")) != 'undefined' && $("#printBtn").length > 0){
			  $("#printBtn").unbind("click");
			  $("#printBtn").bind("click", function() {
	              $(".Mask").show();
			      ajax.init().success(function(code,msg,data){
			          if(code==0){
			              var param=data.filePath+data.fileId+"."+data.fileExt;   
			              $("#alertMessage").text(msg);
			              $(".alertDelete").show();
			              $("#apply").off("click");
			              $("#apply").on("click",function(){                                                  
			                  window.location.href=BASEPATH+"/download/file/"+param;
			                  $(".alertDelete").hide();
			                  $(".Mask").hide();
			                  $(".error").text("下载成功！").show().delay(1000).hide(0);
			              });         
			                $(".Mask,#cancel").click(function(){
			                    $(".alertDelete").hide();
			                });
			          }
			      }).error(function(code, msg, data) {
			          setTimeout(function() {
			              $(this).attr("disabled", false)
			          }, 1000);
			          $(".error").text("打印失败！").show().delay(1000).hide(0);
			      }).post(BASEPATH+"/oa/act/print/printprocess.htm",{"businessId":businessId})
			  })
		  }
		  
		//绑定终止按钮事件
		if (typeof($("#endProcess")) != 'undefined' && $("#endProcess").length > 0) {
			$("#endProcess").unbind("click");
			$("#endProcess").bind("click", function() {
				var btnName = $(this).find('span').text();
				submit.checkForm(this, btnName, "",null, function(data) {
					require.async('resource/js/component/ajax.js', function(ajax) {
						ajax.init().success(function(code, msg, datas) {
								if (code == 0) {
									//处理任务后关闭页签并刷新待办任务页签
									$(".error").text(btnName+"成功").show().delay(1000).hide(0);
									setTimeout(function() {
										submit.goBack();
										}, 1000);
								} else {
									$(".error").text(msg).show().delay(1000).hide(0);
								}

							}).error(function(code, msg, datas) {
								enableBtn()
								$(".error").text("拒绝失败！").show().delay(1000).hide(0);
							}).contentType('application/json')
							.post(BASEPATH + '/oa/act/activitiMain/endProcess.htm', JSON.stringify(data));
					});
				});

			});
		}
		
		//绑定提交事件
		if (typeof($(".assignRoleProcess")) != 'undefined' && $(".assignRoleProcess").length > 0) {	
			$(".assignRoleProcess").unbind("click");
			$(".assignRoleProcess").bind("click", function(){
				var btnName = $(this).val()||$(this).find('span').text();
				var param = "";
				if($(this).data('options')){
					param = JSON.stringify($(this).data('options'));
				}
				submit.checkForm(this, btnName, param,null);								
			})

		}
		//转发事件
		if(typeof($('#transfer')) != 'undefined' &&$('#transfer').length > 0 ){
			$("#addTranfer").listpanel({
				url: BASEPATH + "/base/authoriza/user/getUserListByDeptId.htm",
				dataFilter: function(data) {
					data = data.data;
					for (var i in data) {
						if (data[i].type != 'USER') {
							data[i].noCheck = true;
							data[i].icon = "icon-group";
						}
					}
					return data;
				},
				view: {
					idKey: "id",
					nameKey: "name",
					pidKey: "pid"
				},
				check: {
					type: "radio",
				},
				onSave: function(nodes) {
					disableBtn();
					var checked = nodes[0].id.toString(); 
					if($('#currentUserId').val().toString().trim() == checked.trim()){
						enableBtn();
						$(".error").text('不能转交给自己').show().delay(1000).hide(0);
						return;
					}
					ajax.init().success(function(code,msg,data){
						if(code=='0'){						
							$(".error").text(msg).show().delay(1000).hide(0);
							setTimeout(function() {
								submit.goBack();
							}, 1000);							
						}else{
							enableBtn();
							$(".error").text(msg).show().delay(1000).hide(0);
						}
					}).post(BASEPATH+"/oa/act/activitiMain/transfer.htm",{taskId:$("#taskId").val(),userId:nodes[0].id.toString()});
					}
			});
			$("#transfer").unbind("click");
			$("#transfer").bind('click',function(){
				if($(this).hasClass("l-btn-disabled")){
					return;
				}
				$("#addTranfer").listpanel("show")
			});	
		}
		//挂起事件
		if (typeof($("#hangUp")) != 'undefined' && $("#hangUp").length > 0) {
			$("#hangUp").unbind("click");
			$("#hangUp").bind("click", function() {
				if($(this).hasClass("l-btn-disabled")){
					return;
				}
				disableBtn();
				ajax.init().success(function(code, msg, datas) {
					if (code == 0) {
						$(".error").text("挂起成功！").show().delay(1000).hide(0);
						setTimeout(function() {							
							window.location.reload();
						}, 1000);
					} else {
						enableBtn();
						$(".error").text(msg).show().delay(1000).hide(0);
					}
				}).error(function(code, msg, datas) {
					enableBtn();
					$(".error").text("挂起失败！").show().delay(1000).hide(0);
				}).post(BASEPATH + '/oa/act/activitiMain/hangUp.htm', {
					processInstanceId: processInstanceId,
					businessId: bussId,
					isHangUp: true
				});
			});
			//解挂事件
		} else if (typeof($("#unHangUp")) != 'undefined' && $("#unHangUp").length > 0) {
			$('#btns').find('.approval-button').hide();
			$("#unHangUp").show();
			$("#unHangUp").bind("click", function() {
				if($(this).hasClass("l-btn-disabled")){
					return;
				}
				disableBtn();
				var hangUpUser = $("#hangUpUser").val();
				if (hangUpUser == currentUser) {
					require.async('resource/js/component/ajax.js', function(ajax) {
						ajax.init().success(function(code, msg, datas) {
								if (code == 0) {
									$(".error").text("解挂成功！").show().delay(2000).hide(0);
									setTimeout(function() {
										window.location.reload();
									}, 1000);
								} else {
									enableBtn();
									$(".error").text(msg).show().delay(1000).hide(0);
								}
							}).error(function(code, msg, datas) {
								enableBtn();
								if (code == 12) {
									$(".error").text("您不是挂起人，无权解挂该任务！").show().delay(1000).hide(0);
								} else{
									$(".error").text("解挂失败！").show().delay(1000).hide(0);
								}
							})
							.post(BASEPATH + '/oa/act/activitiMain/hangUp.htm', {
								processInstanceId: processInstanceId,
								businessId: bussId,
								isHangUp: false
							});
					});
				} else {
					enableBtn();
					$(".error").text("您不是挂起人，无权解挂该任务！").show().delay(2000).hide(0);
				}

			});
		} else {}
		
		//更多按钮
		if(typeof($('moreBtns')) != 'undefined' && $("#moreBtns").length > 0){
			disableBtn();
			$('#moreBtns').unbind('click');
			$('#moreBtns').bind('click',function(){
				showMask();
				$('#btnsDlg').show();
			});
		}

	}
	
	exports.init=function (){
		initpage();
	}
	
});